package Test;
import Common.DriverCommon;
import org.neo4j.driver.*;
import org.neo4j.driver.types.Node;

public class Neo4jSetCenterPointBatch {
        public static void main(String[] args) {
            String filedName = "centerPoint";
            try (DriverCommon driverCommon = new DriverCommon()) {
                Driver driver = driverCommon.getGraphDatabase();
                try (Session session = driver.session()) {
                    try (Transaction tx = session.beginTransaction()) {
                        String cypherQuery = "MATCH (n) WHERE n.position IS NOT NULL RETURN n";
                        Result result = tx.run(cypherQuery);

                        while (result.hasNext()) {
                            Record record = result.next();
                            Node node = record.get("n").asNode();
                            String bbox =  String.valueOf(node.get("position"));
                            System.out.println(bbox);

//                            // 执行设置中心点方法
//                            CenterPointDTO centerPoint = Neo4jSetCenterPointUtil.calculateCenter(bbox);

                           // 第二阶段: 将格式化后的值更新回数据库
                            String updateQuery = "MATCH (n) " +
                                    " WHERE id(n) =  "+node.id() +
//                                    " SET n."+filedName+" = " + centerPoint.toString()+
                                    " RETURN n ";
                            tx.run(updateQuery);
                        }
                        // 提交事务
                        tx.commit();
                    }
                }
            }
    }
}


